package com.geologyoa.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Iterator;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.XMLWriter;

import com.geologyoa.domain.Dwqk01;
import com.geologyoa.domain.Dwzz01;
import com.geologyoa.service.SystemManager;
import com.geologyoa.service.SystemManagerImpl;

public class SerachDwzz01Servlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
         doPost(request,response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		SystemManager sys=new SystemManagerImpl();
		String DWZZ0102=request.getParameter("DWZZ0102");//单位统一编号
		String DWZZ0103=request.getParameter("DWZZ0103");//单位名称
		String DWZZ0104=request.getParameter("DWZZ0104");//资质类型
		String DWZZ0105=request.getParameter("DWZZ0105");//资质等级
		String DWZZ0106=request.getParameter("DWZZ0106");//证书标号
		String DWZZ0109=request.getParameter("DWZZ0109");//有效期
		
		List<Dwzz01> dwzzList=sys.SerachDwzz(DWZZ0102,DWZZ0103,DWZZ0104,DWZZ0105,DWZZ0106,DWZZ0109);
		Document document=DocumentHelper.createDocument();
		if(dwzzList!=null)
		{
			Element fwlistElement =document.addElement("dwzzList");
			fwlistElement.addAttribute("size", (new StringBuilder(String.valueOf(dwzzList.size()))).toString());
			Dwzz01 dwzz01;
			Element fwElement;
			for(Iterator iterator=dwzzList.iterator();iterator.hasNext();)
			{
				dwzz01 = (Dwzz01)iterator.next();
				fwElement=fwlistElement.addElement("dwzzInfo");
				fwElement.addAttribute("DWZZ0101", dwzz01.getDwzz0101().toString());
				fwElement.addAttribute("DWZZ0102", dwzz01.getDwzz0102());
				fwElement.addAttribute("DWZZ0103", dwzz01.getDwzz0103());
				fwElement.addAttribute("DWZZ0104", dwzz01.getDwzz0104());
				fwElement.addAttribute("DWZZ0105", dwzz01.getDwzz0105());
				fwElement.addAttribute("DWZZ0106", dwzz01.getDwzz0106());
				fwElement.addAttribute("DWZZ0107", dwzz01.getDwzz0107());
				fwElement.addAttribute("DWZZ0108", dwzz01.getDwzz0108());
				fwElement.addAttribute("DWZZ0109", dwzz01.getDwzz0109());
				fwElement.addAttribute("DWZZ0118", dwzz01.getDwzz0118());
				fwElement.addAttribute("DWZZ0119", dwzz01.getDwzz0119());
				fwElement.addAttribute("DWZZ0120", dwzz01.getDwzz0120());
			}
		}
		StringWriter xmlout = new StringWriter();
		XMLWriter output = new XMLWriter(xmlout);
		output.write(document);
		response.setContentType("text/html;charset=utf-8");
		response.setHeader("Cache-Control", "no-cache");
		response.setHeader("Expires", "0");
		response.setHeader("Pragma", "No-cache");
		response.getWriter().write(xmlout.toString());
	}

}
